package ink.lovejinhu.leetcodeMatch;

import java.util.Arrays;

/**
 * @Author: jin
 * @Date: 2021/8/29 10:48
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_5484 {
    public int minimumDifference(int[] nums, int k) {
        if (k <= 1) return 0;
        Arrays.sort(nums);
        int min = Integer.MAX_VALUE;
        for (int i = 0, j = k - 1; j < nums.length; i++, j++) {
            if (nums[j] - nums[i] < min) {
                min = nums[j] - nums[i];
            }
        }
        return min;
    }
}
